<%@ taglib uri="/WEB-INF/tlds/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/tlds/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/tlds/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/tlds/struts-layout.tld" prefix="layout" %>
<%@page import="com.ds.sbtl.constantes.Constantes" %>
<%@page import="com.ds.sbtl.vo.Catalogos" %>
<%@page import="java.util.*" %>
<%
	String Error = (String)request.getAttribute(Constantes.ERROR);
	String messageError = "/jsp/layout/message.jsp";
	String Exito = (String)request.getAttribute(Constantes.EXITO);
	
	List<Catalogos> categoriasDiv = (List<Catalogos>)request.getAttribute(Constantes.LISTA_CATEGORIAS);
	List<Catalogos> perfilesDiv = (List<Catalogos>)request.getAttribute(Constantes.LISTA_PERFIL);
%>



<DIV id="popCal" style="BORDER-RIGHT: 2px ridge; BORDER-TOP: 2px ridge; Z-INDEX: 100; VISIBILITY: hidden; BORDER-LEFT: 2px ridge; WIDTH: 10px; BORDER-BOTTOM: 2px ridge; POSITION: absolute" 
	onclick="event.cancelBubble=true">

	<IFRAME name=popFrame src="<%=request.getContextPath()%>/jsp/personal/calendarPop.html" frameBorder=0 width=253 scrolling=no height=230></IFRAME>
</DIV>
<SCRIPT event="onclick()" for="document">popCal.style.visibility = "hidden";</SCRIPT>

<script language="JavaScript" src="<%=request.getContextPath()%>/utils/scripts/cotizaciones.js"></script>

<%if (Error != null || Exito !=null){%>
<table width="100%" >
  <tr>
    <td align="center">
      <jsp:include flush="true" page="<%=messageError%>"></jsp:include>
    </td>
  </tr>
</table>
<%}%>


<html:form action="cotizacion.do?reqCode=ingresaCotizacion">
	<table width="100%" cellpadding="2" cellspacing="2" border="0">

	<tr>
		<logic:notEmpty name="<%=Constantes.FORMA_COTIZACION%>" property="id">
					<td style="color:red"><bean:message key="sbtl.numReg"/></td>
					<td><bean:write name="<%=Constantes.FORMA_COTIZACION%>" property="id"/>
					<html:hidden property="id" />
					</td>
					
					<html:hidden property="fechaCreacionS" />
					<html:hidden property="fechaODTS" />
					
					<td style="color:red"><bean:message key="sbtl.usuarioReg"/></td>
					<td><bean:write name="<%=Constantes.FORMA_COTIZACION%>" property="usuario.usuario"/>
					<html:hidden property="usuario.usuario" />
					<html:hidden property="estatus" />
					</td>
		</logic:notEmpty>	
	</tr>			
	
	<tr>
	<td>&nbsp;</td>
	</tr>	
		<tr>
			<td style="font-weight: bold"><bean:message key="sbtl.proveedor"/></td>
		    <td style="font-weight: bold"><bean:message key="sbtl.SBTL"/></td>
			<td style="font-weight: bold"><bean:message key="sbtl.razonSocialProveedor"/></td>
		    <td style="font-weight: bold"><bean:message key="sbtl.razonSocialSBTL"/></td>		
		</tr>
		  
		  								
		<tr> 
		  
			<td><bean:message key="sbtl.fechaIngreso"/></td>
		    <td>
				<html:text property="fechaIngresoS" maxlength="10" size="20" styleId="fechaIngresoS"  onkeyup="this.value=formateafecha(this.value)"></html:text>
						<img src="<%=request.getContextPath()%>/img/calendario.gif" width="20" height="22" 
		  					onclick="popFrame.fPopCalendar(fechaIngresoS,fechaIngresoS,popCal);return false">&nbsp;dd/mm/yyyy
			
			</td>
			
			<td style="font-weight: bold"><bean:message key="sbtl.elaboro"/></td>
		    <td style="font-weight: bold"><bean:message key="sbtl.razonSocialSBTL"/></td>
		</tr>		  
			
			
		<tr>
		 	<td style="font-weight: bold">*<bean:message key="sbtl.evento"/></td>
		    <td>
				<html:text property="evento" maxlength="200" size="40"></html:text>
			</td>
			<td style="font-weight: bold">*<bean:message key="sbtl.fuerzaVenta"/></td>
		   <td>
				<html:select property="fuerzaVenta.id">
					<html:option value="0"><bean:message key="opcion.seleccione"/></html:option>
					<html:options collection="<%=Constantes.LISTA_CLIENTE%>" property="id" labelProperty="razonSocial"/>
				</html:select>
	 	   </td>
			
		</tr>
		  
		<tr>

			<td><bean:message key="sbtl.lugarEvento"/></td>
		    <td>
				<html:text property="lugarEvento" maxlength="200" size="40"></html:text>
			</td>
			
			<td><bean:message key="sbtl.direccionEvento"/></td>
		    <td>
				<html:text property="direccionEvento" maxlength="45" size="40"></html:text>
			</td>
			
		</tr>
		
		<tr>
		
		<td style="font-weight: bold">*<bean:message key="sbtl.porcentajeCom"/></td>
		    <td>
				<html:text property="porcentajeComision" styleId="porcentajeComision" maxlength="6" size="40"
				onchange="cambioEnTotales()"></html:text>
			</td>
			
			<td><bean:message key="sbtl.horarioPersonal"/></td>
		    <td>
				<html:text property="horarioPersonal" maxlength="100" size="40"></html:text>
			</td>
			
		 </tr>
			
	<logic:equal name="<%=Constantes.FORMA_COTIZACION%>" property="estatus" value="2">
		<tr>
			<td colspan="4">&nbsp;</td>
	  </tr>
	 	<tr>
			<td align="left"><bean:message key="sbtl.observaciones"/></td>
			<td colspan="3">
				<html:textarea property="observaciones" cols="50" rows="3"></html:textarea>
			</td>
	  </tr>	  
			
	</logic:equal>
			<tr>
		<td colspan="4">&nbsp;</td>
	  </tr>
	  <tr>
		<td colspan="4">&nbsp;</td>
	  </tr>
	  
	  
	  
	  
		<tr>
			<td colspan=4 align=left valign="top">
				<table width="100%" cellpadding="2" cellspacing="2" border="5">
		  			<tr>	
		  				<td valign="top">
		  					<table width="100%" cellpadding="2" cellspacing="2" border="0">
		  						<tr>
		  							<td colspan="2" align=center valign="top">
		  								<font size=3 color=red >Rango de fechas del Evento</font><br>
		  								<HR width=100% align="left" color="red">
		  							</td>
		  						</tr>
		  						<tr>
		 						 	<td colspan="2" align=right valign="top">
										<a href="javascript:addRango()">Agregar Rango</a>
									</td>
								</tr>
								
								<tr>
								  	<td colspan="2" align=center valign="top">	
										<table width="100%" cellpadding="2" cellspacing="2" border="0">
											<tr> 
												<td class="pleca"><bean:message key="sbtl.inicio"/></td>
												<td class="pleca"><bean:message key="sbtl.final"/></td>
											</tr> 
											<tr> 
												<td align=center>dd/mm/yyyy</td>
												<td align=center>dd/mm/yyyy</td>
											</tr>
											
											<tr>
												<td colspan=2>
													<div id="myDiv">
														<%int i = 0; %>
														<logic:notEmpty name="<%=Constantes.LISTA_RANGOS%>">
															<logic:iterate id="rangos" name="<%=Constantes.LISTA_RANGOS%>">
																<div id="myDiv<%=++i%>">
																	<table width="100%" cellpadding="2" cellspacing="2" border="0">
																		<tr>
																			<td>
																				<input type="hidden" name="valida<%=i%>" id="valida<%=i%>" value="1">
																				<input type="text" maxlength="10" size="10" name="inicio<%=i%>"
																				value="<bean:write name="rangos" property="descRango1"/>"  
																				onkeyup="this.value=formateafecha(this.value)"/>
																			</td>
																			<td>
																				<input type="text" maxlength="10" size="10" name="final<%=i%>"
																				value="<bean:write name="rangos" property="descRango2"/>"  
																				onkeyup="this.value=formateafecha(this.value)"/>
																			</td>
																			<td width="20px" align='center'>
																				<a href="javascript:removeElement('myDiv<%=i%>')" style='color:RED'>X</a>
																			</td>
																		</tr>
																	</table>
																</div>
															</logic:iterate>
														</logic:notEmpty>
														<input value="<%=i%>" id="theValue" name="theValue" type="hidden">
													</div>
												</td>				
											</tr>										
										</table>
		  							</td>
		  						</tr>
		  					</table>
		  				</td>
		  				<td valign="top">
		  					<table width="100%" cellpadding="2" cellspacing="2" border="0">
		  						<tr>
		  							<td colspan="8" align=center valign="top">
		  								<font size=3 color=red >Datos de la Cotizacion</font><br>
		  								<HR width=100% align="left" color="red">
		  							</td>
		  						</tr>
		  						<tr>
		 							<td colspan="8" align=right valign="top">
										<a href="javascript:addDatos()">Agregar Datos</a>
		  							</td>
								</tr>
								<tr>
									<td colspan="8"></td>
		  						</tr>
		  						<tr>
									<td align="center" class="pleca" width="100px"><bean:message key="sbtl.categoria" /></td>
									<td align="center" class="pleca" width="100px"><bean:message key="sbtl.perfil" /></td>
									<td align="center" class="pleca" width="50px"><bean:message key="sbtl.cantidad"/></td>
									<td align="center" class="pleca" width="50px"><bean:message key="sbtl.horas"/></td>
									<td align="center" class="pleca" width="50px"><bean:message key="sbtl.dias"/></td>
									<td align="center" class="pleca" width="50px"><bean:message key="sbtl.precioUnitario"/></td>
									<td align="center" class="pleca" width="100px"><bean:message key="sbtl.importeTotalA"/></td>
									<td width='20px' align='center' class="pleca">-</td>
								</tr>
		  						<tr>
									<td colspan="8">
										<div id="my2Div">
											<%int j = 0;%>
											<logic:notEmpty name="<%=Constantes.LISTA_DATOSCOTIZACION%>">
												<logic:iterate id="datos" name="<%=Constantes.LISTA_DATOSCOTIZACION%>">
													<bean:define id="idCategoria" name="datos" property="idCategoria.id"></bean:define>
													<bean:define id="idPerfil" name="datos" property="idPerfil.id"></bean:define>
													<div id="my2Div<%=++j%>">
														<table width="100%" align="left" cellpadding="0" cellspacing="1">
															<tr>
																<td align="left" width="100px">
																<input type="hidden" name="validar<%=j%>" id="validar<%=j%>" value="1">
																	<SELECT NAME="categoria<%=j%>" SIZE=1>
																		<logic:iterate id="categorias" name="<%=Constantes.LISTA_CATEGORIAS%>"> 
																			<bean:define id="idCat" name="categorias" property="id"></bean:define>
																			<OPTION VALUE="<bean:write name="categorias" property="id"/>" 
																			<%=pageContext.getAttribute("idCat").toString().equals(pageContext.getAttribute("idCategoria").toString())? "selected='selected'":"" %>>
																				<bean:write name="categorias" property="descripcion"/>
																			</OPTION> 
																		</logic:iterate>
																	</SELECT>
																</td>
																<td align="left" width="100px">
																	<SELECT NAME="perfil<%=j%>" SIZE=1>
																		<logic:iterate id="perfiles" name="<%=Constantes.LISTA_PERFIL%>">
																			<bean:define id="idPer" name="perfiles" property="id"></bean:define> 
																			<OPTION VALUE="<bean:write name="perfiles" property="id"/>" 
																			<%=pageContext.getAttribute("idPer").toString().equals(pageContext.getAttribute("idPerfil").toString())? "selected='selected'":"" %>>
																				<bean:write name="perfiles" property="descripcion"/>
																			</OPTION> 
																		</logic:iterate>
																	</SELECT>
																</td>
																<td align='left' width="50px">
																	<input type="text" maxlength="5" size="5" name="cantidad<%=j%>" id="cantidad<%=j%>"
																	value="<bean:write name="datos" property="cantidad"/>" onchange="cambioEnTotales()"/>
																</td>
																<td align='left' width="50px">
																	<input type="text" maxlength="5" size="5" name="horas<%=j%>" id="horas<%=j%>"
																	value="<bean:write name="datos" property="horas"/>" onchange="cambioEnTotales()"/>
																</td>
																<td align='left' width="50px">
																	<input type="text" maxlength="5" size="5" name="dias<%=j%>" id="dias<%=j%>"
																	value="<bean:write name="datos" property="dias"/>" onchange="cambioEnTotales()"/>
																</td>
																<td align='left' width="50px">
																	<input type="text" maxlength="5" size="5" name="precioUnitario<%=j%>" id="precioUnitario<%=j%>"
																	value="<bean:write name="datos" property="precioUnitario"/>" onchange="cambioEnTotales()"/>
																</td>
																<td align='center' width="100px">
																	$<label id="importeTotalA<%=j%>"></label>
																</td>
																<td width='20px' align='center'>
																	<a href="javascript:removeElementDatos('my2Div<%=j%>')" style='color:RED'>X</a>
																	<script type="text/javascript">
																		validaCampos('numeros', ['cantidad<%=j%>', 'horas<%=j%>', 'dias<%=j%>']);
																	    validaCampos('float', ['precioUnitario<%=j%>']);
																	</script>
																</td>
															</tr>
														</table>
									  				</div>		
												</logic:iterate>
											</logic:notEmpty>
										</div>
									</td>
								</tr>
								<tr>
									<td align="right" colspan="6">
										<b>Importe</b>
									</td>
									<td align="right">
										$<label id="LabelImporte">0.00</label>
									</td>
									<td >&nbsp;</td>
								</tr>
								<tr>
									<td align="right" colspan="6">
										<b>% de Comisi&oacute;n</b>
									</td>
									<td align="right">
										$<label id="LabelComision">0.00</label>
									</td>
									<td >&nbsp;</td>
								</tr>
								<tr>
									<td align="right" colspan="6">
										<b>Total</b>
									</td>
									<td align="right">
										$<label id="LabelTotal">0.00</label>
									</td>
									<td >&nbsp;</td>
								</tr>
		  					</table>
		  					<input value="<%=j%>" id="theValue2" name="theValue2" type="hidden">
		  			</td>
		  		</tr>
		  	</table>	
		</td>		  				
	 </tr>			 	
		
		
		
		
		
	
	<logic:equal name="<%=Constantes.FORMA_COTIZACION%>" property="estatus" value="2">
		           
	<tr>	 
				
		<td colspan=3 align="center" valign="top" >
				<table width="100%" cellpadding="0" cellspacing="1" border="0">
					<tr>
						<td align="left" colspan=2>
							<br><br><br ><font  size=3 color=red >Material a Utilizar</font><br>
		  					<HR width=100% align="left" color="red">
						</td>
					</tr>
					<tr>
								<td>&nbsp;</td> 
							<td class="pleca" ><bean:message key="sbtl.cantidad"/></td>
							<td class="pleca"><bean:message key="sbtl.descripcion"/></td>
							<td class="pleca"><bean:message key="sbtl.stock"/></td>
					</tr>
							
							
							
								<%int row = -1;%>
								<logic:iterate id="inventarios"  name="<%=Constantes.MAPA_INVENTARIOS %>">
									<tr>
											<td>
												<input type="checkbox" value="<bean:write name="inventarios" property="id"/>"  name="materialesU"
												<logic:notEmpty name="inventarios" property="cantUtilizar">
													checked="checked"
												</logic:notEmpty> 
												onclick="habilitarCantidad(this, '<bean:write name="inventarios" property="id"/>')">
											</td>
																																						
											<td><input type="text" maxlength="7"  size="8" id="cantUtilizar<bean:write name="inventarios" property="id"/>"  
											name="cantUtilizar<bean:write name="inventarios" property="id"/>"
											value="<bean:write name="inventarios" property="cantUtilizar"/>"
											<logic:empty name="inventarios" property="cantUtilizar">
												disabled="disabled"
											</logic:empty> 
											/></td> 
										 
											<td><bean:write name="inventarios" property="descripcion"/>&nbsp;</td>
											<td><bean:write name="inventarios" property="cantidad"/></td> 
									</tr>
								
								</logic:iterate>
								
						</table>
							
		</td>
		
	</tr>	 
	
	</logic:equal>	
	
	
	  	
		 		  
	<tr>
		<td colspan="4">&nbsp;</td>
	  </tr>
	 					  
					  
		  <tr>
			<td colspan="4" align="right">
				<logic:notEmpty name="<%=Constantes.FORMA_COTIZACION%>" property="id">
						<a href="#" class="tooltip"><input type="image" src="<%=request.getContextPath()%>/img/impresora.gif" onclick="imprimir()"><span>Imprimir</span></a>
						&nbsp;
						</logic:notEmpty>
					<a href="#" class="tooltip"><input type="image" src="<%=request.getContextPath()%>/img/GUARDAR.gif" onclick="javascrit:document.<%=Constantes.FORMA_COTIZACION%>.target='';showMist()"><span>Guardar Registro</span></a>
					&nbsp;
					<logic:notEqual name="<%=Constantes.FORMA_COTIZACION%>" property="estatus" value="2">
						<a href="#" onclick="javascript:document.<%=Constantes.FORMA_COTIZACION%>.target='';showMist();location='<%=request.getContextPath()%>/cotizacion.do?reqCode=consulta'" class="tooltip"><img alt="" src="<%=request.getContextPath()%>/img/rewind.gif" border="0"><span>Ir a consultas</span></a>
					</logic:notEqual>
					<logic:equal name="<%=Constantes.FORMA_COTIZACION%>" property="estatus" value="2">
						<a href="#" onclick="javascript:document.<%=Constantes.FORMA_COTIZACION%>.target='';showMist();location='<%=request.getContextPath()%>/odt.do?reqCode=consulta'" class="tooltip"><img alt="" src="<%=request.getContextPath()%>/img/rewind.gif" border="0"><span>Ir a consultas</span></a>
					</logic:equal>
				</td>
		  </tr>
		  
	</table>
</html:form>

<script type="text/javascript">
    cambioEnTotales();

 function imprimir(){
    	var form = document.<%=Constantes.FORMA_COTIZACION%>;
    	form.target='blank';
    	form.action='cotizacion.do?reqCode=imprimir';
    	form.submit();
    }
	function addDatos(){
		  var ni2 = document.getElementById('my2Div');
		  var numi2 = document.getElementById('theValue2');
		  var num2 = document.getElementById('theValue2').value;
		  num2= Number(num2) + 1;
		  numi2.value = num2;
		  var divIdName2 = "my2Div"+num2;
		  var newdiv2 = document.createElement('div');
		  newdiv2.setAttribute("id",divIdName2);

		  var inner2 = "<table width='100%' align='left' cellpadding='0' cellspacing='1'>"+
			  			"<tr>"+
						"	<td align='left' width='100px'>"+
						"<input type='hidden' name='validar"+num2+"' id='validar"+num2+"' value='1'>"+
						"	<SELECT NAME='categoria"+num2+"' SIZE=1> ";
						<%for(Catalogos categoria:categoriasDiv){%>
							inner2 = inner2 + " <OPTION VALUE='<%=categoria.getId().toString()%>'><%=categoria.getDescripcion()%></OPTION>";
						<%}%>
		  inner2 = inner2 + "	</SELECT>"+
						"</td>"+
						"<td align='left' width='100px'>"+
						"	<SELECT NAME='perfil"+num2+"' SIZE=1>";
					  	<%for(Catalogos perfil:perfilesDiv){%>
							inner2 = inner2 + " <OPTION VALUE='<%=perfil.getId().toString()%>'><%=perfil.getDescripcion()%></OPTION>";
						<%}%>
		  inner2 = inner2 + "	</SELECT>"+
						"</td>"+
						"<td align='left' width='50px'>"+
						"	<input type='text' maxlength='5' size='5' name='cantidad"+num2+"' id='cantidad"+num2+"' onchange='cambioEnTotales()'/>"+
						"</td>"+
						"<td align='left' width='50px'>"+
						"	<input type='text' maxlength='5' size='5' name='horas"+num2+"' id='horas"+num2+"' onchange='cambioEnTotales()'/>"+
						"</td>"+
						"<td align='left' width='50px'>"+
						"	<input type='text' maxlength='5' size='5' name='dias"+num2+"' id='dias"+num2+"' onchange='cambioEnTotales()'/>"+
						"</td>"+
						"<td align='left' width='50px'>"+
						"	<input type='text' maxlength='8' size='8' name='precioUnitario"+num2+"' id='precioUnitario"+num2+"' onchange='cambioEnTotales()'/>"+
						"</td>"+
						"<td align='center' width='100px'>"+
						"	$<label id='importeTotalA"+num2+"'>0.00</label>"+
						"</td>"+
						"	<td width='20px' align='center'>"+
						"		<a href=\"javascript:removeElementDatos('my2Div"+num2+"')\" style='color:RED'>X</a>"+		
						"	</td>"+
						"</tr> "+
						"</table>";						
						
		  newdiv2.innerHTML = inner2;
		  ni2.appendChild(newdiv2);

		  validaCampos('numeros', ['cantidad'+num2, 'horas'+num2, 'dias'+num2]);
		  validaCampos('float', ['precioUnitario'+num2]);
	}
	
	
	validaCampos("float", ["porcentajeComision"]);
	
	
</script>